package Thread;

public class ThreadDemo4 {
    public static void main(String[] args) {
        Thread thread = new Thread(){//{}意思是定义一个类，这个类继承自Thread，此处最主要的目的是重写run方法,与此同时还创建了一个子类的实例

            @Override
            public void run() {
                while (true) {
                    System.out.println("Hello Thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        thread.start();
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
